<?php

function VerifierAdresseMail($adresse)
{
	$Syntaxe='#^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,6}$#';
	if(preg_match($Syntaxe,$adresse))
	return 1;
	else
	return 0;
}

/*******************************************************
 * Fonction : getOs
 *----------------------------------------------
 * @Desc : Retourne le nom de l'os grâce à l'user agent
 * @Param : $ua (str) : l'user agent dont on veux trouver l'os
 * @Return : (str) le nom de l'os trouvé sinon "Système d'exploitation inconnu"
 * @licence : http://opensource.org/licenses/lgpl-license.php GNU LGPL
 *********************************************************/
function getOS( $ua = '' )
{
	if( ! $ua ) $ua = $_SERVER['HTTP_USER_AGENT'];
	$os = 'Système d\' exploitation inconnu';
	$os_arr = Array(
	// -- Windows
'Windows NT 6.1' => 'Windows Seven',
'Windows NT 6.0' => 'Windows Vista',
'Windows NT 5.2' => 'Windows Server 2003',
'Windows NT 5.1' => 'Windows XP',
'Windows NT 5.0' => 'Windows 2000',
'Windows 2000' => 'Windows 2000',
'Windows CE' => 'Windows Mobile',
'Win 9x 4.90' => 'Windows Me.',
'Windows 98' => 'Windows 98',
'Windows 95' => 'Windows 95',
'Win95' => 'Windows 95',
'Windows NT' => 'Windows NT',
	// -- Linux
'Ubuntu' => 'Linux Ubuntu',
'Fedora' => 'Linux Fedora',
'Linux' => 'Linux',
	// -- Mac
'Macintosh' => 'Mac',
'Mac OS X' => 'Mac OS X',
'Mac_PowerPC' => 'Mac OS X',
	// -- Autres ...
'FreeBSD' => 'FreeBSD',
'Unix' => 'Unix',
'Playstation portable' => 'PSP',
'OpenSolaris' => 'SunOS',
'SunOS' => 'SunOS',
'Nintendo Wii' => 'Nintendo Wii',
'Mac' => 'Mac',
	);
	$ua = strtolower( $ua );
	foreach( $os_arr as $k => $v )
	{
		if( ereg( strtolower( $k ), $ua ) )
		{
			$os = $v;
			break;
		}
	}
	return $os;
}

/**
 * Fichier contenant les fonctions generiques cross-project
 */

if ($_POST == "" && $HTTP_POST_VARS != "")
$_POST = $HTTP_POST_VARS;

/* function recuperer_variable
 *
 * comment
 *
 */
function recuperer_variable($p_nom_variable, $p_defaut) {
	if (isset($_REQUEST[$p_nom_variable]))
	$variable = $_REQUEST[$p_nom_variable];
	else {
		if (isset($_POST[$p_nom_variable]))
		$variable = $_POST[$p_nom_variable];
		else {
			if (isset($_SESSION[$p_nom_variable]))
			$variable = $_SESSION[$p_nom_variable];
			else
			if (isset($_COOKIE[$p_nom_variable]))
			$variable = $_COOKIE[$p_nom_variable];
			else
			$variable = $p_defaut;
		}
	}
	return $variable;
}


/* function prendre_temps
 *
 * comment
 *
 */
function prendre_temps() {
	list($usec, $sec) = explode(" ",microtime());
	return ((float)$usec + (float)$sec);
}


/**
 *
 * @abstract : print html interval de temps en seconde entre 2 appel + memoire utilisÃ©e
 * @param string $msg
 * @return NULL
 *
 */
function laps($msg = ""){
	$admin = recuperer_variable("administrateur", "");
	 
	if(strtoupper($admin->nom) != "KERISIT") return;
	 
	static $depart = 0;

	$arrive = microtime(true);
	$temps = $arrive -$depart;

	if($depart == 0){
		$msg = "Init laps";
		$temps = 0;
	}
	 
	$depart = $arrive;
	 
	printf("<p style=\"color : blue\">%f secondes <i>%s</i> (memoire : %s octets)</p>\n", $temps, $msg, memory_get_usage());//debug
}


/* function date_courte_fr
 *
 * comment
 *
 */
function date_courte_fr($p_date_en) {
	$result = "";
	$x = explode("-", $p_date_en);
	$result = sprintf("%s/%s/%s", $x[2], $x[1], $x[0]);
	return $result;
}

function date_mois_afficher_nom($p_nombre, $p_abrege) {
	switch ($p_nombre) {
		case 1  : $p_abrege == 1 ? $txt = "Janv." : $txt = "Janvier"; break;
		case 2  : $p_abrege == 1 ? $txt = "F&eacute;vr." : $txt = "F&eacute;vrier"; break;
		case 3  : $p_abrege == 1 ? $txt = "Mars" : $txt = "Mars"; break;
		case 4  : $p_abrege == 1 ? $txt = "Avr." : $txt = "Avril"; break;
		case 5  : $p_abrege == 1 ? $txt = "Mai" : $txt = "Mai"; break;
		case 6  : $p_abrege == 1 ? $txt = "Juin" : $txt = "Juin"; break;
		case 7  : $p_abrege == 1 ? $txt = "Juil." : $txt = "Juillet"; break;
		case 8  : $p_abrege == 1 ? $txt = "Ao&ucirc;t" : $txt = "Ao&ucirc;t"; break;
		case 9  : $p_abrege == 1 ? $txt = "Sept." : $txt = "Septembre"; break;
		case 10 : $p_abrege == 1 ? $txt = "Oct." : $txt = "Octobre"; break;
		case 11 : $p_abrege == 1 ? $txt = "Nov." : $txt = "Novembre"; break;
		case 12 : $p_abrege == 1 ? $txt = "D&eacute;c." : $txt = "D&eacute;cembre"; break;
		default : $txt = "Mois inconnu (" . $p_nombre . ")"; break;
	}
	return $txt;
}

/* function date_courte_texte
 *
 * comment
 *
 */
function date_courte_texte($p_date_en) {
	$result = "";
	$x = explode("-", $p_date_en);
	switch ($x[1]) {
		case 1 :
			$mois = "Jan.";
			break;
		case 2 :
			$mois = "Fev.";
			break;
		case 3 :
			$mois = "Mar.";
			break;
		case 4 :
			$mois = "Avr.";
			break;
		case 5 :
			$mois = "Mai.";
			break;
		case 6 :
			$mois = "Juin";
			break;
		case 7 :
			$mois = "Juil.";
			break;
		case 8 :
			$mois = "Aou.";
			break;
		case 9 :
			$mois = "Sept.";
			break;
		case 10 :
			$mois = "Oct.";
			break;
		case 11 :
			$mois = "Nov.";
			break;
		case 12 :
			$mois = "Dec.";
			break;
	}
	$result = sprintf("%s %s %s", $x[2], $mois, $x[0]);
	return $result;
}


/* function date_longue_fr
 *
 * comment
 *
 */
function date_longue_fr($p_date_en) {
	$result = "";
	$x = explode(" ", $p_date_en);
	$y = explode("-", $x[0]);
	$result = sprintf("%s/%s/%s %s", $y[2], $y[1], $y[0], $x[1]);
	return $result;

}


/* function datefr2en
 *
 *  comment
 *
 */
function datefr2en($mydate){
	@list($jour,$mois,$annee) = explode('/',$mydate);
	return @date($annee.'-'.$mois.'-'.$jour);
}


/* function dateen2fr
 *
 *  comment
 *
 */
function dateen2fr($mydate){
	@list($annee,$mois,$jour) = explode('-',$mydate);
	return @date($jour.'/'.$mois.'/'.$annee);
}


/* function afficher_nombre_entier
 *
 *  comment
 *
 */
function afficher_nombre_entier($p_nombre) {
	return number_format($p_nombre, 0, ',', ' ');
}


/* function afficher_nombre_flottant
 *
 *  comment
 *
 */
function afficher_nombre_flottant($p_nombre) {
	return number_format($p_nombre, 2, ',', ' ');
}


/*
 * function encoder_XML
 *  comment
 *
 */
function encoder_XML($p_txt) {
	$txt = $p_txt;
	$txt = str_replace("&", "&amp;", $txt);
	$txt = str_replace("<", "&lt;", $txt);
	$txt = str_replace(">", "&gt;", $txt);
	$txt = str_replace("\"", "&quot;", $txt);
	$txt = str_replace("'", "&apos;", $txt);
	return $txt;
}


/* function encoder_txt_log
 *
 *  comment
 *
 */
function encoder_txt_log($p_txt) {
	$txt = $p_txt;
	$txt = str_replace("|", "-", $txt);
	$txt = str_replace("\r\n", " ", $txt);
	$txt = str_replace("\n", " ", $txt);
	$txt = str_replace(chr(10), " ", $txt);
	$txt = str_replace(chr(13), " ", $txt);
	$txt = str_replace("\"", "\"\"", $txt);
	return $txt;
}


/* function decoder_txt_log
 *
 *  comment
 *
 */
function decoder_txt_log($p_txt) {
	$txt = $p_txt;
	$txt = str_replace("\"\"", "\"", $txt);

	if (substr($txt, 0, 1) == "\"") {
		// texte entoure de doubles quotes a enlever
		$txt = substr($txt, 1, 100000);
		if (substr($txt, -1, 1) == "\"")
		$txt = substr($txt, 0, -1);
	}
	$txt = trim($txt);
	return $txt;
}


/* function sans_accent
 *
 *  comment
 *
 */
function sans_accent($p_chaine) {

	return sans_accentUtf8($p_chaine);//on n'utilise plus cette fonction car l'encodage du projet est alignÃ©

	$entree = $sortie = "";
	$entree .= chr(225); // a aigu
	$sortie .= "a";
	$entree .= chr(193); // A aigu
	$sortie .= "A";
	$entree .= chr(226); // a circonflexe
	$sortie .= "a";
	$entree .= chr(194); // A circonflexe
	$sortie .= "A";
	$entree .= chr(224); // a agrave
	$sortie .= "a";
	$entree .= chr(192); // A agrave
	$sortie .= "A";
	$entree .= chr(229); // a norvegien
	$sortie .= "a";
	$entree .= chr(197); // A norvegien
	$sortie .= "A";
	$entree .= chr(227); // a espagnol
	$sortie .= "a";
	$entree .= chr(195); // A espagnol
	$sortie .= "A";
	$entree .= chr(228); // a trema
	$sortie .= "a";
	$entree .= chr(196); // A trema
	$sortie .= "A";
	$entree .= chr(231); // c cedille
	$sortie .= "c";
	$entree .= chr(199); // C cedille
	$sortie .= "C";
	$entree .= chr(233); // e aigu
	$sortie .= "e";
	$entree .= chr(201); // E aigu
	$sortie .= "E";
	$entree .= chr(234); // e circonflexe
	$sortie .= "e";
	$entree .= chr(202); // E circonflexe
	$sortie .= "E";
	$entree .= chr(232); // e agrave
	$sortie .= "e";
	$entree .= chr(200); // E agrave
	$sortie .= "E";
	$entree .= chr(235); // e trema
	$sortie .= "e";
	$entree .= chr(203); // E trema
	$sortie .= "E";
	$entree .= chr(237); // i aigu
	$sortie .= "i";
	$entree .= chr(205); // I aigu
	$sortie .= "I";
	$entree .= chr(238); // i circonflexe
	$sortie .= "i";
	$entree .= chr(206); // I circonflexe
	$sortie .= "I";
	$entree .= chr(236); // i agrave
	$sortie .= "i";
	$entree .= chr(204); // I agrave
	$sortie .= "I";
	$entree .= chr(239); // i trema
	$sortie .= "i";
	$entree .= chr(207); // I trema
	$sortie .= "I";
	$entree .= chr(241); // n espagnol
	$sortie .= "n";
	$entree .= chr(209); // N espagnol
	$sortie .= "N";
	$entree .= chr(243); // o aigu
	$sortie .= "o";
	$entree .= chr(211); // O aigu
	$sortie .= "O";
	$entree .= chr(244); // o circonflexe
	$sortie .= "o";
	$entree .= chr(212); // O circonflexe
	$sortie .= "O";
	$entree .= chr(242); // o agrave
	$sortie .= "o";
	$entree .= chr(210); // O agrave
	$sortie .= "O";
	$entree .= chr(248); // o norvegien
	$sortie .= "o";
	$entree .= chr(216); // O norvegien
	$sortie .= "O";
	$entree .= chr(245); // o espagnol
	$sortie .= "o";
	$entree .= chr(213); // O espagnol
	$sortie .= "O";
	$entree .= chr(246); // o trema
	$sortie .= "o";
	$entree .= chr(214); // O trema
	$sortie .= "O";
	$entree .= chr(250); // u aigu
	$sortie .= "u";
	$entree .= chr(218); // U aigu
	$sortie .= "U";
	$entree .= chr(251); // u circonflexe
	$sortie .= "u";
	$entree .= chr(219); // U circonflexe
	$sortie .= "U";
	$entree .= chr(249); // u agrave
	$sortie .= "u";
	$entree .= chr(217); // U agrave
	$sortie .= "U";
	$entree .= chr(252); // u trema
	$sortie .= "u";
	$entree .= chr(220); // U trema
	$sortie .= "U";
	$entree .= chr(191); // interrogation a l'envers
	$sortie .= " ";
	$entree .= chr(161); // exclamation a l'envers
	$sortie .= " ";
	$entree .= chr(174); // guillement ouvrant
	$sortie .= "\"";
	$entree .= chr(175); // guillement fermant
	$sortie .= "\"";
	$entree .= chr(247); // divise
	$sortie .= "/";
	$entree .= chr(178); // 2 exposant
	$sortie .= "2";
	$entree .= chr(176); // degre
	$sortie .= "o";

	$result = trim(strtr($p_chaine, $entree, $sortie));

	$result = str_replace(chr(230), "ae", $result);
	$result = str_replace(chr(198), "Ae", $result);
	$result = str_replace(chr(156), "oe", $result);
	$result = str_replace(chr(140), "Oe", $result);
	$result = str_replace(chr(163), "livres", $result);
	$result = str_replace(chr(165), "yen", $result);
	$result = str_replace(chr(128), "euro", $result);
	$result = str_replace(chr(36), "dollar", $result);

	return $result;
}


/**
 *
 * @param $p_chaine
 */
function sans_accentUtf8($p_chaine){

	/*

	//XXX : ajouter des caractÃ¨res ci-dessous au besoin


	Ã€ //LATIN CAPITAL LETTER A WITH GRAVE
	Ã� //LATIN CAPITAL LETTER A WITH ACUTE
	Ã‚ //LATIN CAPITAL LETTER A WITH CIRCUMFLEX
	Ãƒ //LATIN CAPITAL LETTER A WITH TILDE
	Ã„ //LATIN CAPITAL LETTER A WITH DIAERESIS
	Ã… //LATIN CAPITAL LETTER A WITH RING ABOVE
	Ä€ //LATIN CAPITAL LETTER A WITH MACRON
	Ä„ //LATIN CAPITAL LETTER A WITH OGONEK
	Ä‚ //LATIN CAPITAL LETTER A WITH BREVE
	Ã† //LATIN CAPITAL LETTER AE
	Ã‡ //LATIN CAPITAL LETTER C WITH CEDILLA
	Ä† //LATIN CAPITAL LETTER C WITH ACUTE
	ÄŒ //LATIN CAPITAL LETTER C WITH CARON
	Äˆ //LATIN CAPITAL LETTER C WITH CIRCUMFLEX
	ÄŠ //LATIN CAPITAL LETTER C WITH DOT ABOVE
	ÄŽ //LATIN CAPITAL LETTER D WITH CARON
	Ä� //LATIN CAPITAL LETTER D WITH STROKE
	Ãˆ //LATIN CAPITAL LETTER E WITH GRAVE
	Ã‰ //LATIN CAPITAL LETTER E WITH ACUTE
	ÃŠ //LATIN CAPITAL LETTER E WITH CIRCUMFLEX
	Ã‹ //LATIN CAPITAL LETTER E WITH DIAERESIS
	Ä’ //LATIN CAPITAL LETTER E WITH MACRON
	Ä˜ //LATIN CAPITAL LETTER E WITH OGONEK
	Äš //LATIN CAPITAL LETTER E WITH CARON
	Ä” //LATIN CAPITAL LETTER E WITH BREVE
	Ä– //LATIN CAPITAL LETTER E WITH DOT ABOVE
	Äœ //LATIN CAPITAL LETTER G WITH CIRCUMFLEX
	Äž //LATIN CAPITAL LETTER G WITH BREVE
	Ä  //LATIN CAPITAL LETTER G WITH DOT ABOVE
	Ä¢ //LATIN CAPITAL LETTER G WITH CEDILLA
	Ä¤ //LATIN CAPITAL LETTER H WITH CIRCUMFLEX
	Ä¦ //LATIN CAPITAL LETTER H WITH STROKE
	ÃŒ //LATIN CAPITAL LETTER I WITH GRAVE
	Ã� //LATIN CAPITAL LETTER I WITH ACUTE
	ÃŽ //LATIN CAPITAL LETTER I WITH CIRCUMFLEX
	Ã� //LATIN CAPITAL LETTER I WITH DIAERESIS
	Äª //LATIN CAPITAL LETTER I WITH MACRON
	Ä¨ //LATIN CAPITAL LETTER I WITH TILDE
	Ä¬ //LATIN CAPITAL LETTER I WITH BREVE
	Ä® //LATIN CAPITAL LETTER I WITH OGONEK
	Ä° //LATIN CAPITAL LETTER I WITH DOT ABOVE
	Ä² //LATIN CAPITAL LIGATURE IJ
	Ä´ //LATIN CAPITAL LETTER J WITH CIRCUMFLEX
	Ä¶ //LATIN CAPITAL LETTER K WITH CEDILLA
	Å� //LATIN CAPITAL LETTER L WITH STROKE
	Ä½ //LATIN CAPITAL LETTER L WITH CARON
	Ä¹ //LATIN CAPITAL LETTER L WITH ACUTE
	Ä» //LATIN CAPITAL LETTER L WITH CEDILLA
	Ä¿ //LATIN CAPITAL LETTER L WITH MIDDLE DOT
	Ã‘ //LATIN CAPITAL LETTER N WITH TILDE
	Åƒ //LATIN CAPITAL LETTER N WITH ACUTE
	Å‡ //LATIN CAPITAL LETTER N WITH CARON
	Å… //LATIN CAPITAL LETTER N WITH CEDILLA
	ÅŠ //LATIN CAPITAL LETTER ENG
	Ã’ //LATIN CAPITAL LETTER O WITH GRAVE
	Ã“ //LATIN CAPITAL LETTER O WITH ACUTE
	Ã” //LATIN CAPITAL LETTER O WITH CIRCUMFLEX
	Ã• //LATIN CAPITAL LETTER O WITH TILDE
	Ã– //LATIN CAPITAL LETTER O WITH DIAERESIS
	Ã˜ //LATIN CAPITAL LETTER O WITH STROKE
	ÅŒ //LATIN CAPITAL LETTER O WITH MACRON
	Å� //LATIN CAPITAL LETTER O WITH DOUBLE ACUTE
	ÅŽ //LATIN CAPITAL LETTER O WITH BREVE
	Å’ //LATIN CAPITAL LIGATURE OE
	Å” //LATIN CAPITAL LETTER R WITH ACUTE
	Å˜ //LATIN CAPITAL LETTER R WITH CARON
	Å– //LATIN CAPITAL LETTER R WITH CEDILLA
	Åš //LATIN CAPITAL LETTER S WITH ACUTE
	Å  //LATIN CAPITAL LETTER S WITH CARON
	Åž //LATIN CAPITAL LETTER S WITH CEDILLA
	Åœ //LATIN CAPITAL LETTER S WITH CIRCUMFLEX
	È˜ //LATIN CAPITAL LETTER S WITH COMMA BELOW
	Å¤ //LATIN CAPITAL LETTER T WITH CARON
	Å¢ //LATIN CAPITAL LETTER T WITH CEDILLA
	Å¦ //LATIN CAPITAL LETTER T WITH STROKE
	Èš //LATIN CAPITAL LETTER T WITH COMMA BELOW
	Ã™ //LATIN CAPITAL LETTER U WITH GRAVE
	Ãš //LATIN CAPITAL LETTER U WITH ACUTE
	Ã› //LATIN CAPITAL LETTER U WITH CIRCUMFLEX
	Ãœ //LATIN CAPITAL LETTER U WITH DIAERESIS
	Åª //LATIN CAPITAL LETTER U WITH MACRON
	Å® //LATIN CAPITAL LETTER U WITH RING ABOVE
	Å° //LATIN CAPITAL LETTER U WITH DOUBLE ACUTE
	Å¬ //LATIN CAPITAL LETTER U WITH BREVE
	Å¨ //LATIN CAPITAL LETTER U WITH TILDE
	Å² //LATIN CAPITAL LETTER U WITH OGONEK
	Å´ //LATIN CAPITAL LETTER W WITH CIRCUMFLEX
	Ã� //LATIN CAPITAL LETTER Y WITH ACUTE
	Å¶ //LATIN CAPITAL LETTER Y WITH CIRCUMFLEX
	Å¸ //LATIN CAPITAL LETTER Y WITH DIAERESIS
	Å¹ //LATIN CAPITAL LETTER Z WITH ACUTE
	Å½ //LATIN CAPITAL LETTER Z WITH CARON
	Å» //LATIN CAPITAL LETTER Z WITH DOT ABOVE







	Ã  //LATIN SMALL LETTER A WITH GRAVE
	Ã¡ //LATIN SMALL LETTER A WITH ACUTE
	Ã¢ //LATIN SMALL LETTER A WITH CIRCUMFLEX
	Ã£ //LATIN SMALL LETTER A WITH TILDE
	Ã¤ //LATIN SMALL LETTER A WITH DIAERESIS
	Ã¥ //LATIN SMALL LETTER A WITH RING ABOVE
	Ä� //LATIN SMALL LETTER A WITH MACRON
	Ä… //LATIN SMALL LETTER A WITH OGONEK
	Äƒ //LATIN SMALL LETTER A WITH BREVE
	Ã¦ //LATIN SMALL LETTER AE
	Ã§ //LATIN SMALL LETTER C WITH CEDILLA
	Ä‡ //LATIN SMALL LETTER C WITH ACUTE
	Ä� //LATIN SMALL LETTER C WITH CARON
	Ä‰ //LATIN SMALL LETTER C WITH CIRCUMFLEX
	Ä‹ //LATIN SMALL LETTER C WITH DOT ABOVE
	Ä� //LATIN SMALL LETTER D WITH CARON
	Ä‘ //LATIN SMALL LETTER D WITH STROKE
	Ã¨ //LATIN SMALL LETTER E WITH GRAVE
	Ã© //LATIN SMALL LETTER E WITH ACUTE
	Ãª //LATIN SMALL LETTER E WITH CIRCUMFLEX
	Ã« //LATIN SMALL LETTER E WITH DIAERESIS
	Ä“ //LATIN SMALL LETTER E WITH MACRON
	Ä™ //LATIN SMALL LETTER E WITH OGONEK
	Ä› //LATIN SMALL LETTER E WITH CARON
	Ä• //LATIN SMALL LETTER E WITH BREVE
	Ä— //LATIN SMALL LETTER E WITH DOT ABOVE
	Æ’ //LATIN SMALL LETTER F WITH HOOK
	Ä� //LATIN SMALL LETTER G WITH CIRCUMFLEX
	ÄŸ //LATIN SMALL LETTER G WITH BREVE
	Ä¡ //LATIN SMALL LETTER G WITH DOT ABOVE
	Ä£ //LATIN SMALL LETTER G WITH CEDILLA
	Ä¥ //LATIN SMALL LETTER H WITH CIRCUMFLEX
	Ä§ //LATIN SMALL LETTER H WITH STROKE
	Ã¬ //LATIN SMALL LETTER I WITH GRAVE
	Ã­ //LATIN SMALL LETTER I WITH ACUTE
	Ã® //LATIN SMALL LETTER I WITH CIRCUMFLEX
	Ã¯ //LATIN SMALL LETTER I WITH DIAERESIS
	Ä« //LATIN SMALL LETTER I WITH MACRON
	Ä© //LATIN SMALL LETTER I WITH TILDE
	Ä­ //LATIN SMALL LETTER I WITH BREVE
	Ä¯ //LATIN SMALL LETTER I WITH OGONEK
	Ä± //LATIN SMALL LETTER DOTLESS I
	Ä³ //LATIN SMALL LIGATURE IJ
	Äµ //LATIN SMALL LETTER J WITH CIRCUMFLEX
	Ä· //LATIN SMALL LETTER K WITH CEDILLA
	Ä¸ //LATIN SMALL LETTER KRA
	Å‚ //LATIN SMALL LETTER L WITH STROKE
	Ä¾ //LATIN SMALL LETTER L WITH CARON
	Äº //LATIN SMALL LETTER L WITH ACUTE
	Ä¼ //LATIN SMALL LETTER L WITH CEDILLA
	Å€ //LATIN SMALL LETTER L WITH MIDDLE DOT
	Ã± //LATIN SMALL LETTER N WITH TILDE
	Å„ //LATIN SMALL LETTER N WITH ACUTE
	Åˆ //LATIN SMALL LETTER N WITH CARON
	Å† //LATIN SMALL LETTER N WITH CEDILLA
	Å‰ //LATIN SMALL LETTER N PRECEDED BY APOSTROPHE
	Å‹ //LATIN SMALL LETTER ENG
	Ã² //LATIN SMALL LETTER O WITH GRAVE
	Ã³ //LATIN SMALL LETTER O WITH ACUTE
	Ã´ //LATIN SMALL LETTER O WITH CIRCUMFLEX
	Ãµ //LATIN SMALL LETTER O WITH TILDE
	Ã¶ //LATIN SMALL LETTER O WITH DIAERESIS
	Ã¸ //LATIN SMALL LETTER O WITH STROKE
	Å� //LATIN SMALL LETTER O WITH MACRON
	Å‘ //LATIN SMALL LETTER O WITH DOUBLE ACUTE
	Å� //LATIN SMALL LETTER O WITH BREVE
	Å“ //LATIN SMALL LIGATURE OE
	Å• //LATIN SMALL LETTER R WITH ACUTE
	Å™ //LATIN SMALL LETTER R WITH CARON
	Å— //LATIN SMALL LETTER R WITH CEDILLA
	Å› //LATIN SMALL LETTER S WITH ACUTE
	Å¡ //LATIN SMALL LETTER S WITH CARON
	ÅŸ //LATIN SMALL LETTER S WITH CEDILLA
	Å� //LATIN SMALL LETTER S WITH CIRCUMFLEX
	È™ //LATIN SMALL LETTER S WITH COMMA BELOW
	Å¥ //LATIN SMALL LETTER T WITH CARON
	Å£ //LATIN SMALL LETTER T WITH CEDILLA
	Å§ //LATIN SMALL LETTER T WITH STROKE
	È› //LATIN SMALL LETTER T WITH COMMA BELOW
	Ã¹ //LATIN SMALL LETTER U WITH GRAVE
	Ãº //LATIN SMALL LETTER U WITH ACUTE
	Ã» //LATIN SMALL LETTER U WITH CIRCUMFLEX
	Ã¼ //LATIN SMALL LETTER U WITH DIAERESIS
	Å« //LATIN SMALL LETTER U WITH MACRON
	Å¯ //LATIN SMALL LETTER U WITH RING ABOVE
	Å± //LATIN SMALL LETTER U WITH DOUBLE ACUTE
	Å­ //LATIN SMALL LETTER U WITH BREVE
	Å© //LATIN SMALL LETTER U WITH TILDE
	Å³ //LATIN SMALL LETTER U WITH OGONEK
	Åµ //LATIN SMALL LETTER W WITH CIRCUMFLEX
	Ã½ //LATIN SMALL LETTER Y WITH ACUTE
	Ã¿ //LATIN SMALL LETTER Y WITH DIAERESIS
	Å· //LATIN SMALL LETTER Y WITH CIRCUMFLEX
	Å¾ //LATIN SMALL LETTER Z WITH CARON
	Å¼ //LATIN SMALL LETTER Z WITH DOT ABOVE
	Åº //LATIN SMALL LETTER Z WITH ACUTE

	Ãž //LATIN CAPITAL LETTER THORN
	Ã¾ //LATIN SMALL LETTER THORN
	ÃŸ //LATIN SMALL LETTER SHARP S
	Å¿ //LATIN SMALL LETTER LONG S
	Ã� //LATIN CAPITAL LETTER ETH
	Ã° //LATIN SMALL LETTER ETH

	*/
	$normalizeChars = array(
'Ã '=>'a',   // a aigu
'Ã€'=>'A',   // A aigu
'Ã¢'=>'a',   // a circonflexe
'Ã‚'=>'A',   // A circonflexe
'Ã '=>'a',   // a agrave
'Ã€'=>'A',   // A agrave
'Ã¥'=>'a',   // a norvegien
'Ã…'=>'A',   // A norvegien
'Ã£'=>'a',   // a espagnol
'Ãƒ'=>'A',   // A espagnol
'Ã¤'=>'a',   // a trema
'Ã„'=>'A',   // A trema
'Ã§'=>'c',   // c cedille
'Ã‡'=>'C',   // C cedille
'Ã©'=>'e',   // e aigu
'Ã‰'=>'E',   // E aigu
'Ãª'=>'e',   // e circonflexe
'ÃŠ'=>'E',   // E circonflexe
'Ã¨'=>'e',   // e agrave
'Ãˆ'=>'E',   // E agrave
'Ã«'=>'e',   // e trema
'Ã‹'=>'E',   // E trema
'Ã­'=>'i',   // i aigu
'Ã�'=>'I',   // I aigu
'Ã®'=>'i',   // i circonflexe
'ÃŽ'=>'I',   // I circonflexe
'Ã¬'=>'i',   // i agrave
'ÃŒ'=>'I',   // I agrave
'Ã¯'=>'i',   // i trema
'Ã�'=>'I',   // I trema
'Ã±'=>'n',   // n espagnol
'Ã‘'=>'N',   // N espagnol
'Ã³'=>'o',   // o aigu
'Ã“'=>'O',   // O aigu
'Ã´'=>'o',   // o circonflexe
'Ã”'=>'O',   // O circonflexe
'Ã²'=>'o',   // o agrave
'Ã’'=>'O',   // O agrave
'Ã¸'=>'o',   // o norvegien
'Ã˜'=>'O',   // O norvegien
'Ãµ'=>'o',   // o espagnol
'Ã•'=>'O',   // O espagnol
'Ã¶'=>'o',   // o trema
'Ã–'=>'O',   // O trema
'Ãº'=>'u',   // u aigu
'Ãš'=>'U',   // U aigu
'Ã»'=>'u',   // u circonflexe
'Ã›'=>'U',   // U circonflexe
'Ã¹'=>'u',   // u agrave
'Ã™'=>'U',   // U agrave
'Ã¼'=>'u',   // u trema
'Ãœ'=>'U',   // U trema

'Â¿'=>' ',   // interrogation a l'envers
'Â¡'=>' ',   // exclamation a l'envers
'Â«'=>'"',   // guillement ouvrant
'Â»'=>'"',   // guillement fermant
'â€˜'=>'"',   // guillement ouvrant simple
'â€™'=>'"',   // guillement fermant simple
'â€œ'=>'"',   // guillement ouvrant double
'â€�'=>'"',   // guillement fermant double
'â€²'=>'\'',  // prime
'Â´'=>'\'',  // accent aigue

'Ã·'=>'/',   // divise
'Â²'=>'2',   // 2 exposant
'Â°'=>'o',   // degre

	//ligatures
'Ã¦'=>'ae',
'Ã†'=>'Ae',
'Å“'=>'oe',
'Å’'=>'Oe',

	//devises
'Â£'=>'livres',
'Â¥'=>'yen',
'â‚¬'=>'euro',
'Â€'=>'euro',//character invisible sous eclipse, â‚¬ issu de l'iso affichÃ© en utf8
'$'=>'dollar'
	);
	$result = strtr($p_chaine, $normalizeChars);

	$result = cleanNonBreakingSpaces($result);
	return $result;
}

/**
 *

 \s by default, will not match whitespace characters with values greater than 128. To get at those, you can instead make good use of other UTF-8-aware sequences.

 (Standard disclaimer: I'm skimming the PCRE source code to compile the lists below, I may miss a character or type something incorrectly. Please forgive me.)

 \p{Zs} matches:

 U+0020 Space
 U+00A0 No-break space
 U+1680 Ogham space mark
 U+180E Mongolian vowel separator
 U+2000 En quad
 U+2001 Em quad
 U+2002 En space
 U+2003 Em space
 U+2004 Three-per-em space
 U+2005 Four-per-em space
 U+2006 Six-per-em space
 U+2007 Figure space
 U+2008 Punctuation space
 U+2009 Thin space
 U+200A Hair space
 U+202F Narrow no-break space
 U+205F Medium mathematical space
 U+3000 Ideographic space

 \h (Horizontal whitespace) matches the same as \p{Zs} above, plus

 U+0009 Horizontal tab.

 Similarly for matching vertical whitespace there are a few options.

 \p{Zl} matches U+2028 Line separator.

 \p{Zp} matches U+2029 Paragraph separator.

 \v (Vertical whitespace) matches \p{Zl}, \p{Zp} and the following

 U+000A Linefeed
 U+000B Vertical tab
 U+000C Formfeed
 U+000D Carriage return
 U+0085 Next line
 *
 */
function cleanNonBreakingSpaces($text)
{
	$text = preg_replace('/[\p{Z}\p{Zs}\p{Zl}\p{Zp}\h\v]/u',' ',$text);
	$text = preg_replace('/\s+/u',' ',$text);

	return $text;
}

// php decode a partir du charset de ISO-8859-1 et le symbole euro appartient au charset ISO-8859-15.
function mon_UTF8_encode($p_texte) {
	$texte = $p_texte;
	return $texte;//on n'utilise plus cette fonction car l'encodage du projet est alignÃ©
	 
	$texte = str_replace("â‚¬", "&euro;", $texte);
	$texte = utf8_encode($texte);
	$texte = str_replace("&euro;", "â‚¬", $texte);

	return $texte;
}

function mon_UTF8_decode($p_texte) {
	$texte = $p_texte;
	return $texte;//on n'utilise plus cette fonction car l'encodage du projet est alignÃ©

	$texte = str_replace("â‚¬", "&euro;", $texte);
	$texte = str_replace("Å“", "&oelig;", $texte);
	$texte = str_replace("â€™", "&#146;", $texte); // apostrophe
	$texte = str_replace("â€“", "&tiret;", $texte); // tiret
	$texte = str_replace("â€¦", "...", $texte); // point de suspension
	//$texte = str_replace("+", "&plus;", $texte);

	$texte = utf8_decode($texte);
	 
	$texte = str_replace("&euro;", "â‚¬", $texte);
	$texte = str_replace("&oelig;", "oe", $texte);
	$texte = str_replace("&#146;", "'", $texte); // apostrophe
	$texte = str_replace("&tiret;", "-", $texte);
	 
	//$texte = str_replace("&plus;", "+", $texte);
	 
	return $texte;
}

/*
 * debug function
 * sorte de var_dump
 * liste un tableau/objet sur toutes ces profondeurs
 */
function ListageArray($tb)
{
	echo "<ul>";
	//Pour chaque Ã©lÃ©ment du tableau...
	foreach($tb as $key => $value)
	{
		$object = false;
		if(is_object($value)){
			$value = (array) $value;
			$object = true;
		}
		//... si l'Ã©lÃ©ment est un tableau, on appelle la fonction pour qu'elle le parcours
		if(is_array($value))
		{
			echo "\n <li><ul><li><b>\$key : $key</b>";
			if($object === true)echo "<i> (object)</i>";
			echo "</li>\n";
			ListageArray($value);
			echo "</ul></li>\n";
		}
		else//...Sinon, c'est un Ã©lÃ©ment Ã  afficher, alors on le liste !
		{
			echo "<li>$key =>".$value."</li>\n";
		}
	}
	echo "</ul>";
}


/**
 *
 * @param string $chaine
 * transforme $chaine en format PCRE insensible aux accents et caractÃ¨res spÃ©ciaux.
 *
 */
function regexAccents($chaine) {
	$accent = array('a','Ã ','Ã¡','Ã¢','Ã£','Ã¤','Ã¥','c','Ã§','e','Ã¨','Ã©','Ãª','Ã«','i','Ã¬','Ã­','Ã®','Ã¯','o','Ã°','Ã²','Ã³','Ã´','Ãµ','Ã¶','u','Ã¹','Ãº','Ã»','Ã¼','y','Ã½','Ã½','Ã¿');
	$inter = array('%01','%02','%03','%04','%05','%06','%07','%08','%09','%10','%11','%12','%13','%14','%15','%16','%17','%18','%19','%20','%21','%22','%23','%24','%25','%26','%27','%28','%29','%30','%31','%32','%33','%34','%35');
	$regex = array('(a|Ã |Ã¡|Ã¢|Ã£|Ã¤|Ã¥)','(a|Ã |Ã¡|Ã¢|Ã£|Ã¤|Ã¥)','(a|Ã |Ã¡|Ã¢|Ã£|Ã¤|Ã¥)','(a|Ã |Ã¡|Ã¢|Ã£|Ã¤|Ã¥)','(a|Ã |Ã¡|Ã¢|Ã£|Ã¤|Ã¥)','(a|Ã |Ã¡|Ã¢|Ã£|Ã¤|Ã¥)','(a|Ã |Ã¡|Ã¢|Ã£|Ã¤|Ã¥)',
                  '(c|Ã§)','(c|Ã§)',
                  '(Ã¨|e|Ã©|Ãª|Ã«)','(Ã¨|e|Ã©|Ãª|Ã«)','(Ã¨|e|Ã©|Ãª|Ã«)','(Ã¨|e|Ã©|Ãª|Ã«)','(Ã¨|e|Ã©|Ãª|Ã«)',
                  '(i|Ã¬|Ã­|Ã®|Ã¯)','(i|Ã¬|Ã­|Ã®|Ã¯)','(i|Ã¬|Ã­|Ã®|Ã¯)','(i|Ã¬|Ã­|Ã®|Ã¯)','(i|Ã¬|Ã­|Ã®|Ã¯)',   
                  '(o|Ã°|Ã²|Ã³|Ã´|Ãµ|Ã¶)','(o|Ã°|Ã²|Ã³|Ã´|Ãµ|Ã¶)','(o|Ã°|Ã²|Ã³|Ã´|Ãµ|Ã¶)','(o|Ã°|Ã²|Ã³|Ã´|Ãµ|Ã¶)','(o|Ã°|Ã²|Ã³|Ã´|Ãµ|Ã¶)','(o|Ã°|Ã²|Ã³|Ã´|Ãµ|Ã¶)','(o|Ã°|Ã²|Ã³|Ã´|Ãµ|Ã¶)',         
                  '(u|Ã¹|Ãº|Ã»|Ã¼)','(u|Ã¹|Ãº|Ã»|Ã¼)','(u|Ã¹|Ãº|Ã»|Ã¼)','(u|Ã¹|Ãº|Ã»|Ã¼)',
                  '(y|Ã½|Ã½|Ã¿)','(y|Ã½|Ã½|Ã¿)','(y|Ã½|Ã½|Ã¿)','(y|Ã½|Ã½|Ã¿)');
	$chaine = str_ireplace($accent, $inter, $chaine);
	$chaine = str_replace($inter, $regex, $chaine);
	return $chaine;
}


// -----------------------------------------------
function construit_exp_reg($p_exp_reg) {
	 
	$exp_reg = $p_exp_reg;
	 
	$les_A = "a" . chr(225) . chr(193) . chr(226) . chr(194) . chr(224) . chr(192) . chr(228) . chr(196);
	$les_E = "e" . chr(233) . chr(201) . chr(234) . chr(202) . chr(232) . chr(200) . chr(235) . chr(203);
	$les_I = "i" . chr(237) . chr(205) . chr(238) . chr(206) . chr(236) . chr(204) . chr(239) . chr(207);
	$les_O = "o" . chr(243) . chr(211) . chr(244) . chr(212) . chr(242) . chr(210) . chr(246) . chr(214);
	$les_U = "u" . chr(250) . chr(218) . chr(251) . chr(219) . chr(249) . chr(217) . chr(252) . chr(220);
	$les_C = "c" . chr(231) . chr(199);
	$les_accents = $les_A . $les_E . $les_I . $les_O . $les_U . $les_C;
	 
	$tb_A = str_split($les_A);
	$tb_E = str_split($les_E);
	$tb_I = str_split($les_I);
	$tb_O = str_split($les_O);
	$tb_U = str_split($les_U);
	$tb_C = str_split($les_C);
	 
	$exp_reg = str_ireplace($tb_A, "#", $exp_reg);
	$exp_reg = str_ireplace("#", "[" . $les_A . "]", $exp_reg);
	$exp_reg = str_ireplace($tb_E, "#", $exp_reg);
	$exp_reg = str_ireplace("#", "[" . $les_E . "]", $exp_reg);
	$exp_reg = str_ireplace($tb_I, "#", $exp_reg);
	$exp_reg = str_ireplace("#", "[" . $les_I . "]", $exp_reg);
	$exp_reg = str_ireplace($tb_O, "#", $exp_reg);
	$exp_reg = str_ireplace("#", "[" . $les_O . "]", $exp_reg);
	$exp_reg = str_ireplace($tb_U, "#", $exp_reg);
	$exp_reg = str_ireplace("#", "[" . $les_U . "]", $exp_reg);
	$exp_reg = str_ireplace($tb_C, "#", $exp_reg);
	$exp_reg = str_ireplace("#", "[" . $les_C . "]", $exp_reg);
	 
	$exp_reg = str_ireplace("mm", "mm?", $exp_reg);
	$exp_reg = str_ireplace("nn", "nn?", $exp_reg);
	$exp_reg = str_ireplace("pp", "pp?", $exp_reg);
	$exp_reg = str_ireplace("ss", "ss?", $exp_reg);
	$exp_reg = str_ireplace("rr", "rr?", $exp_reg);
	$exp_reg = str_ireplace("tt", "tt?", $exp_reg);
	$exp_reg = str_ireplace("bb", "bb?", $exp_reg);
	$exp_reg = str_ireplace("cc", "cc?", $exp_reg);
	$exp_reg = str_replace("dd", "dd?", $exp_reg); // pour eviter le remplacement dans "Cuisine, 1 salle de bain" qui devient "Sddb"
	$exp_reg = str_ireplace("ff", "ff?", $exp_reg);
	$exp_reg = str_ireplace("ll", "ll?", $exp_reg);
	 
	// Mettre un s du pluriel
	if (substr($exp_reg, strlen($exp_reg) - 1, 1) == "s")
	$exp_reg = $exp_reg . "?";

	// Proteger les points qui signifient "n'importe quel caractere" sauf s'il est deja protege
	/*

	while (strpos($exp_reg, "\\.") !== false)
	$exp_reg = str_replace("\\.", "POINT_ESCAPE", $exp_reg);
	while (strpos($exp_reg, ".") !== false)
	$exp_reg = str_replace(".", "\\.", $exp_reg);
	while (strpos($exp_reg, "POINT_ESCAPE") !== false)
	$exp_reg = str_replace("POINT_ESCAPE", "\\.", $exp_reg);
	*/

	//echo $exp_reg . "<br />\n";
	return $exp_reg;
}


// ProtÃ¨ge les / car c'est le caractÃ¨re de dÃ©but et fin d'expression rÃ©guliÃ¨re

function formate_exp_reg($p_exp, $debug, &$trace)
{
	$trace_int = "";
	$trace_int .= sprintf("<formate_exp_reg>\n");
	$trace_int .= sprintf("<entree>%s</entree>\n", $p_exp);
	 
	$exp = construit_exp_reg($p_exp);
	 
	$exp = str_replace("/", "\/", $exp);
	 
	$trace_int .= sprintf("<sortie>%s</sortie>\n", $exp);
	$trace_int .= sprintf("</formate_exp_reg>\n");
	if ($debug) sprintf("<xmp>%s</xmp>", str_replace("<", "&lt;", $trace_int));
	//$trace .= $trace_int;
	 
	return $exp;
}


/*
 * recursiveArraySearch : permet de retrouver une clÃ© correspondant a une valeur dans un tableau multidimensionnel
 * $haystack : le tableau
 * $needle : la valeur recherchÃ©e
 * $index : l'index sur lequel chercher (optionnel)
 */
function recursiveArraySearch($haystack, $needle, $index = null)
{
	$aIt 	= new RecursiveArrayIterator($haystack);
	$it		= new RecursiveIteratorIterator($aIt);

	while($it->valid())
	{
		if (((isset($index) AND ($it->key() == $index)) OR (!isset($index))) AND ($it->current() == $needle)) {
			return $aIt->key();
		}
			
		$it->next();
	}

	return false;
}

/*
 * function array_sort
 * @param $array le tableau a trier
 * @param $on le champ de tri
 * @param $order le sens de trie (SORT_DESC/SORT_ASC)
 * @return le tableau triÃƒÂ©e
 */
function array_sort($array, $on, $order='SORT_DESC')
{
	$new_array = array();
	$sortable_array = array();

	if (count($array) > 0) {
		foreach ($array as $k => $v) {
			if (is_array($v)) {
				foreach ($v as $k2 => $v2) {
					if ($k2 == $on) {
						$sortable_array[$k] = $v2;
					}
				}
			} else {
				$sortable_array[$k] = $v;
			}
		}

		switch($order)
		{
			case 'SORT_ASC':
				//echo "ASC";
				asort($sortable_array);
				break;
			case 'SORT_DESC':
				//echo "DESC";
				arsort($sortable_array);
				break;
		}

		foreach($sortable_array as $k => $v) {
			$new_array[] = $array[$k];
		}
	}
	return $new_array;
}

/*
 * 23-01-2009 Richard Goutorbe
 * http://www.montpellier-informatique.com/
 * $value donnÃ©es brutes (saisies par l'opÃ©rateur) Ã  filtrer
 * valeur de retour: la valeur filtrÃ©e, garantie fiable pour MySql static
 */
function mysql_escape_input($value) {

	if ((!is_null($value)) && strlen($value) > 0) {

		$retval = $value;
		$retval = Htmlentities ($value);
		$retval = utf8_decode($value);
		if (get_magic_quotes_gpc())
		$retval = stripslashes($retval);
		$retval = mysql_real_escape_string($retval);
		$retval = addcslashes($retval, '%_'); // escape jokers du LIKE
		$retval = utf8_encode($retval);
		$retval = html_entity_decode($retval) ;
	}
	else
	$retval = $value;
	return $retval;

}

/**
 *
 */
function htmlvardump(){
	ob_start();
	$var = func_get_args();
	call_user_func_array('var_dump', $var);
	//return htmlentities(ob_get_clean(), ENT_QUOTES, "UTF-8");
	return ob_get_clean();
}

/* function flush_buffers
 *
 *  appeller 1 fois ob_start(); avant d'appeler cette fonction. pour initialiser le buffer
 *
 */
function flush_buffers(){
	ob_end_flush();
	@ob_flush();
	flush();
	ob_start();
}

/**
 *
 * @param string $p_sujet
 * @param string $p_message
 * @param string $p_admin_association_administrateur_taches : nom du champs a verifier dans la table p_admin_association_administrateur_taches
 */
function envoyer_mails_projet ($p_sujet, $p_message, $p_admin_association_administrateur_taches) {
	$connexion = sql_connecter();
	 
	$msg = '';
	$recipient = "";
	 
	if(strstr("@",$p_admin_association_administrateur_taches) == true) $recipient = $p_admin_association_administrateur_taches;
	 
	else{
		// Adresses mail des administrateurs Semantia
		$requete_admin_semantia  = ' SELECT `email` FROM `admin_administrateur` a';
		$requete_admin_semantia .= ' JOIN `admin_association_administrateur_taches` t ON (a.`id_administrateur` = t.`id_administrateur`)';
		$requete_admin_semantia .= sprintf(' WHERE `%s` = 1', $p_admin_association_administrateur_taches);

		$resultat_admin_semantia = sql_executer($connexion,$requete_admin_semantia);

		if (stristr($resultat_admin_semantia, "erreur")|| sql_nombre_lignes($resultat_admin_semantia) == 0) {
			return "Echec lors de la rÃ©cupÃ©ration des adresses des administrateurs Semantia.\n\n $resultat_admin_semantia\n";
		}
		else{
			$sender = "support@semantia.com";
			$from = sprintf('"Semantia - COMAREG" <%s>', $sender);
	   
			while ($ligne_admin_semantia = sql_lire_ligne_objet($resultat_admin_semantia)){
				$recipient .= $ligne_admin_semantia->email .",";
			}
		}
	}

	if($recipient != ""){
		// Headers, etc.
		$headers  = "From: $from\n";
		$headers .= "Reply-To: $sender\n";
		$headers .= "Content-Type: text/plain; charset=\"utf8\"\n";
		$headers .= "Content-Transfer-Encoding: 8bit";

		$envoi = '';
		 
		if (mail ($recipient, $p_sujet, $p_message, $headers)){
			return true;
		}
		else{
			return false;
		}
	}
}



/**
 * @abstract function linked to formatAndHighlightXmlString, escape problematic html tags in CDATA
 * @param array $matches
 * @return string
 * @see formatAndHighlightXmlString
 */
function cleanCDATA($matches){
	 
	if(strpos($matches[2], "CHEDRO") || strpos($matches[2], "CHEGAU") || strpos($matches[2], "GUILLDOU") || strpos($matches[2], "GUILLSIM")){
		$matches[2] = str_replace(array("CHEGAU", "CHEDRO", "GUILLDOU", "GUILLSIM"), array("&lt;", "&gt;", '"', "'"), $matches[2]);
	}
	else{
		$matches[2] = str_replace(array("<", ">", '"', "'"), array("CHEGAU", "CHEDRO", "GUILLDOU", "GUILLSIM"), $matches[2]);
	}
	 
	return $matches[1].$matches[2].$matches[3];
}


/**
 * @abstract : indent and highlight xml string
 * @param string $xml
 */
function formatAndHighlightXmlString($xml) {

	//cleaning all line feed
	$xml = preg_replace('/\R+/', '', $xml);
	$xml = preg_replace('/\r+/', '', $xml);
	$xml = preg_replace('/\n+/', '', $xml);

	//CDATA cleaning avoid html tag-end disturbing process.
	$xml = preg_replace_callback('/(<!\[CDATA\[)(.*?)(]]>)/um', 'cleanCDATA', $xml);

	// add marker linefeeds to aid the pretty-tokeniser (adds a linefeed between all tag-end boundaries)
	$xml = preg_replace('/(>)\s*(<)(\/*)/u', "$1\n$2$3", $xml);
	$xml = preg_replace('/\?>/u', "?>\n", $xml);



	// now indent the tags
	$token      = strtok($xml, "\n");
	$result     = ''; // holds formatted version as it is built
	$pad        = 0; // initial indent
	$matches    = array(); // returns from preg_matches()

	// scan each line and adjust indent based on opening/closing tags
	while ($token !== false) :
	// test for the various tag states
	 
	// 1. CDATA
	if(preg_match('/<!\[CDATA\[.*?]]>/u', $token, $matches)):
	$indent=0;
	// 2. open and closing tags on same line - no change
	elseif (preg_match('/.+<\/\w[^>]*>$/', $token, $matches)) :
	$indent=0;
	// 3. closing tag - outdent now
	elseif (preg_match('/^<\/\w/', $token, $matches)) :
	$pad--;
	$indent=0;
	// 4. opening tag - don't pad this one, only subsequent tags
	elseif (preg_match('/^<\w[^>]*[^\/]>.*$/', $token, $matches)) :
	$indent=1;
	// 5. no indentation needed
	else :
	$indent = 0;
	endif;
	 
	// pad the line with the required number of leading spaces
	//$line    = str_pad($token, strlen($token)+$pad, ' ', STR_PAD_LEFT);
	$line    = str_repeat("~", abs((int) $pad)).$token;
	 
	//      $line = preg_replace_callback('/(<!\[CDATA\[)(.*?)(]]>)/um', 'cleanCDATA', $line);//
	$result .= $line . "\n"; // add to the cumulative result, with linefeed
	$token   = strtok("\n"); // get the next token
	$pad    += $indent; // update the pad size for subsequent lines
	endwhile;

	//double cette ligne du au format du xml
	$result = html_entity_decode($result, ENT_QUOTES, "UTF-8");
	$result = html_entity_decode($result, ENT_QUOTES, "UTF-8");

	$xml = $result;

	//  $xml = preg_replace_callback('/(<!\[CDATA\[)(.+?)(]]>)/', 'cleanCDATA', $xml);

	$xml = htmlspecialchars($xml, ENT_QUOTES, "UTF-8");
	$xml = preg_replace("#&lt;([/]*?)(.*)([\s]*?)&gt;#sU",
        "<font color=\"#0000FF\">&lt;\\1\\2\\3&gt;</font>",$xml);
	$xml = preg_replace("#&lt;([\?])(.*)([\?])&gt;#sU",
        "<font color=\"#800000\">&lt;\\1\\2\\3&gt;</font>",$xml);
	$xml = preg_replace("#&lt;([^\s\?/=])(.*)([\[\s/]|&gt;)#iU",
        "&lt;<font color=\"#808000\">\\1\\2</font>\\3",$xml);
	$xml = preg_replace("#&lt;([/])([^\s]*?)([\s\]]*?)&gt;#iU",
        "&lt;\\1<font color=\"#808000\">\\2</font>\\3&gt;",$xml);
	$xml = preg_replace("#([^\s]*?)\=(&quot;|')(.*)(&quot;|')#isU",
        "<font color=\"#800080\">\\1</font>=<font color=\"#FF00FF\">\\2\\3\\4</font>",$xml);
	$xml = preg_replace("#&lt;(.*)(\[)(.*)(\])&gt;#isU",
        "&lt;\\1<font color=\"#800080\">\\2\\3\\4</font>&gt;",$xml);

	//
	$xml = preg_replace_callback('/(\[CDATA\[)(.+?)(]])/u', 'cleanCDATA', $xml, -1, $c);


	$result = nl2br($xml);

	$result = preg_replace("/&nbsp;+/", " ", $result);
	$result = str_replace("~", "&nbsp;&nbsp;&nbsp;", $result);

	return $result;
}
?>